package abacab.serial;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * Represents a serializer
 */
public interface Serializer {
	/**
	 * @return true if the class name must be provided in the message for deserialization purpose
	 */
	boolean isClassNameNeeded();

	/**
	 * Serialize an object
	 * 
	 * @param obj
	 *          the object to serialize
	 * @param os
	 *          the output stream where the serialized message is written
	 * @throws IOException
	 *           if an error occurred
	 */
	void encode(Object obj, OutputStream os) throws IOException;

	/**
	 * Un-serialize an object
	 * 
	 * @param is
	 *          the input stream where the serialized object is read
	 * @param clazz
	 *          the class of the object
	 * @return the object
	 * @throws IOException
	 *           if an error occurred
	 * @throws ClassNotFoundException
	 *           if the serialized object's class was not found
	 */
	@SuppressWarnings("rawtypes")
	Object decode(InputStream is, Class clazz) throws IOException, ClassNotFoundException;

	/**
	 * Dispose of all resources
	 */
	void dispose();
}